using System;
using System.IO;
using Shell32;

namespace ExcelRefresh
{
    public class ShellFileProperties 
    {
        private readonly Folder _shellFolder;
        private readonly FolderItem2 _folderItem;

        public ShellFileProperties(string filePath)
        {
            if (!File.Exists(filePath))
                throw new FileNotFoundException(filePath);

            var shell = new Shell();
            var fi = new FileInfo(filePath);
            if (fi.Directory == null) throw new FileNotFoundException("File not found", filePath);

            var folderPath = fi.Directory.FullName;
            var fileName = Path.GetFileName(filePath);
            _shellFolder = shell.NameSpace(folderPath);
            _folderItem = (FolderItem2)_shellFolder.ParseName(fileName);
        }

        private string GetDetails(int index)
        {
            return _shellFolder.GetDetailsOf(_folderItem, index); 
        }

        public string Name { get { return GetDetails(0); } }
        public string Size { get { return GetDetails(1); } }
        public string FileType { get { return GetDetails(2); } }
        public DateTime DateModified { get { return DateTime.Parse(GetDetails(3)); } }
        public DateTime DateCreated { get { return DateTime.Parse(GetDetails(4)); } }
        public DateTime DateAccessed { get { return DateTime.Parse(GetDetails(5)); } }
        public string Attributes { get { return GetDetails(6); } }
        public string Status { get { return GetDetails(7); } }
        public string Owner { get { return GetDetails(8); } }
        public string Author { get { return GetDetails(9); } }
        public string Title { get { return GetDetails(10); } }
        public string Subject { get { return GetDetails(11); } }
        public string Category { get { return GetDetails(12); } }
        public string Comments { get { return GetDetails(14); } }
        public string Keywords { get { return GetDetails(40); } }
        public string ContentStatus { get { return GetDetails(126); } }
    }
}